'use strict';
define(function(require, exports, module) {

    // app.directive('player', function() {
    //     return {
    //         'restrict': 'E',
    //         'replace': true,
    //         templateUrl: "tpl/player.html",
    //         link: function(scope, element, attrs) {

    //         }
    //     };
    // });

    /**
     * 注册路由
     */
    function registerRouteState(app, navItems) {
        var states = {};

        angular.forEach(navItems, function(item) {
            // 处理多级state，自动添加各个父级state
            var paths = item.state.split(/\./g);
            var currentPath = '';
            angular.forEach(paths, function(path) {
                currentPath += path;
                states[currentPath] = item;
                currentPath += '.'
            });
        });

        // 遵循约定优于配置的原则自动批量注册路由
        angular.forEach(states, function(item, state) {
            var path = state.replace(/\./g, '/');
            var lastState = state.match(/(\w+)$/)[0];
            app.register.stateProvider.state(state, {
                url: '/' + lastState,
                templateUrl: seajs.data.baseUrl + '/' + path + '/view/' + lastState + '.html',
                resolve: app.getRouteResolve('./' + path + '/mod.js')
            });
        });
    }

    exports.init = function(app) {
        console.info("load app-header...");

        app.register.directive("appHeader", function() {
            return {
                'restrict': 'E',
                'replace': true,
                templateUrl: "common/directive/app-header/view/app-header.html",
                controller: function($scope, $element) {


                }
            };
        });

        //加载路由
        var navItems = [{
            state: "login",
            label: "登录"
        }, {
            state: "register",
            label: "注册"
        }];

        registerRouteState(app, navItems);

    };

});